package huawei.dfs;

import treenode.TreeNode;

public class NC195 {
    private int maxRoute;
    public int diameterOfBinaryTree (TreeNode root) {
        // write code here
        maxRoute=0;
        getDepth(root);
        return maxRoute;

    }

    private int getDepth(TreeNode root){
        if(root==null){
            return 0;
        }
        int left = getDepth(root.left);
        int right =getDepth(root.right);
        int curRoute =left+right;
        maxRoute=Math.max(curRoute,maxRoute);
        return Math.max(left,right)+1;
    }
}
